package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;
import view.AppFrame;

// implement action and window for window and menu item
public class CloseListener implements ActionListener, WindowListener {

    // reference
    private AppFrame guiMain = AppFrame.getSingletonInstance();

    @Override
    public void actionPerformed(ActionEvent arg0) { // when an action fires it
	int confirmed = JOptionPane.showConfirmDialog(guiMain, "Are you sure?",
		"Confirm", JOptionPane.YES_NO_OPTION); // question dialog

	if (confirmed == JOptionPane.YES_OPTION) { // If yes, exit
	    System.exit(0);
	}

    }

    @Override
    public void windowActivated(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

    @Override
    public void windowClosed(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

    @Override
    public void windowClosing(WindowEvent arg0) { // when the window fires it

	int confirmed = JOptionPane.showConfirmDialog(guiMain, "Are you sure?",
		"Confirm", JOptionPane.YES_NO_OPTION); // question dialog

	if (confirmed == JOptionPane.YES_OPTION) {// if yes, exit
	    System.exit(0);
	}

    }

    @Override
    public void windowDeactivated(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

    @Override
    public void windowDeiconified(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

    @Override
    public void windowIconified(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

    @Override
    public void windowOpened(WindowEvent arg0) {
	// TODO Auto-generated method stub

    }

}
